package com.alageek.crowd.mvc.handler;

import com.alageek.crowd.entity.Admin;
import com.alageek.crowd.service.api.AdminService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author alageek
 */
@Controller
public class TestHandler {

    private final AdminService adminService;

    public TestHandler(AdminService adminService) {
        this.adminService = adminService;
    }

    @RequestMapping("send/array.html")
    @ResponseBody
    public String testReceiveArray(@RequestBody List<Integer> array){
        Logger logger = LoggerFactory.getLogger(TestHandler.class);
        for (Integer integer : array) {
            logger.info("num = " + integer);
        }
        return "success";
    }

    @RequestMapping("/test/ssm.html")
    public String ssmTest(ModelMap modelMap){
        List<Admin> adminList = adminService.getAll();
        modelMap.addAttribute("adminList", adminList);
        //System.out.println(10/0);
        return "target";
    }

}
